import axios from 'axios'
import config from '../config'

export function getUserRole(roleId) {
  return axios.get(config.SERVER_URL + window.apiPath + '/user-roles/' + roleId, {responseType: 'json'})
    .then(resp => resp.data)
}

export function findAll(query = '') {
  return axios.get(config.SERVER_URL + window.apiPath + `/user-roles?query=${query}`, {responseType: 'json'})
    .then(resp => resp.data)
}

export function searchp(query, page, pageSize = config.PAGE_SIZE) {
  return axios.get(config.SERVER_URL + window.apiPath + `/user-roles-ps?page=${page}&size=${pageSize}&query=${query}`, {responseType: 'json'})
    .then(resp => {
      return {
        data: resp.data,
        dataCount: parseInt(resp.headers['x-total-count'], 10)
      }
    })
}

export function create(entity) {
  return axios.post(config.SERVER_URL + window.apiPath + '/user-roles', {...entity, responseType: 'json'})
}

export function update(entity) {
  return axios.put(config.SERVER_URL + window.apiPath + '/user-roles', {...entity, responseType: 'json'})
}

export function del(id) {
  return axios.delete(config.SERVER_URL + window.apiPath + '/user-roles/' + id, {responseType: 'json'})
}
